const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const WebpackChunkHash = require('webpack-chunk-hash')

module.exports = function (config, env) {
  // config.module.loaders[0].exclude.push(/\.ejs$/)    // 注 1
  config.output.publicPath = '/';
  config.output.filename = '[name].[chunkhash].js'
  config.output.chunkFilename = '[chunkhash].async.js'
  config.plugins[3] = new ExtractTextPlugin('style.[contenthash:20].css')    // 注 2
  config.plugins.push(
    new HtmlWebpackPlugin({
      template: './src/index.ejs',    // 注 3
      inject: true,
      minify: {collapseWhitespace: true},
      production: true,
    }),
    new WebpackChunkHash({algorithm: 'md5'})
  )


  return config
}
